﻿using System.Collections.Generic;
using System.Data;
using Smatime.Web.DAO.SmatimeDatasetTableAdapters;
using Smatime.Web.Models;

namespace Smatime.Web.DAO
{
    public class HistoryOfUserRepository :
        BaseRepository<HistoryOfUser, SmatimeDataset.HistoryOfUsersDataTable, HistoryOfUsersTableAdapter>
    {
        /// <summary>
        ///     get history list of company
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public IEnumerable<HistoryOfUser> GetHistoryByCompanyId(long id)
        {
            using (var adapter = new HistoryOfUsersTableAdapter())
            {
                using (var table = adapter.GetDataBy(id))
                {
                    var list = new List<HistoryOfUser>();
                    foreach (DataRow row in table.Rows)
                    {
                        var historyOfCompany = new HistoryOfUser();
                        historyOfCompany.FromDataRow(row);
                        list.Add(historyOfCompany);
                    }
                    return list;
                }
            }
        }
    }
}